package com.newly.common.core.aspect;

import com.newly.common.core.service.operLogger.api.IOperLoggerService;
import com.newly.common.core.utils.RequestUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: newly-parent
 * @remark: 操作日志
 * @author: guan
 * @create: 2022-02-07 15:19
 */
@Aspect
@Component
public class NewlyLogAspect {

    @Autowired
    private IOperLoggerService operLoggerService;

    @Autowired
    private RequestUtils requestUtils;

    @Pointcut("@annotation(com.newly.common.base.annotation.NewlyLog)")
    public void pointCut() {
    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) {
        Integer status = null;
        Object proceed = null;
        try {
            proceed = proceedingJoinPoint.proceed();
            status = 1;
        } catch (Throwable e) {
            e.printStackTrace();
            status = 0;
        }
        try {
            operLoggerService.save(proceedingJoinPoint, status);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return proceed;
    }
}
